package com.clear.prototype.shallowcopy.clone;

import com.clear.prototype.shallowcopy.Song;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


/**
 * 具体原型类：实现一个克隆自己的操作（方法）
 * todo  可以重写Object中的clone方法，声明 Cloneable标识接口，表示该类可以被克隆
 */
@Data
public class Playlist2 implements Serializable, Cloneable {
    private Long id;
    private String name;
    private List<Song> songs = new ArrayList<>();

    public Playlist2() {
    }

    public void add(Song song) {
        songs.add(song);
    }


    @Override
    protected Object clone() throws CloneNotSupportedException {
        Playlist2 playList = null;
        try {
            playList = (Playlist2) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
        return playList;
    }
}
